package com.ssy.lingxi.pay.controller.pc;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.pay.model.vo.request.*;
import com.ssy.lingxi.pay.model.vo.response.*;
import com.ssy.lingxi.pay.service.ICreditApplyService;
import com.ssy.lingxi.pay.service.ICreditBillService;
import com.ssy.lingxi.pay.service.ICreditService;
import com.ssy.lingxi.pay.service.ICreditTradeRecordService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * @menu 支付与结算能力-授信申请
 * @author 伍将
 * @date 2020/8/17 16:35
 * @version 2.0.0
 */
@RestController
@RequestMapping("/pay/credit/apply")
public class CreditApplyController extends BaseController {

    @Resource
    private ICreditService creditService;

    @Resource
    private ICreditApplyService creditApplyService;

    @Resource
    private ICreditTradeRecordService tradeRecordService;

    @Resource
    private ICreditBillService billService;

    /**
     * 授信额度管理-分页查询授信信息
     * @author 伍将
     * @date 2020/8/14
     **/
    @RequestMapping(value = "/pageCredit", method = RequestMethod.GET)
    public Wrapper<PageData<CreditQueryVO>> pageCredit(HttpServletRequest httpRequest, @Valid PageQueryCreditVO pageVO) {
        return creditService.pageCredit(getSysUser(httpRequest), pageVO);
    }

    /**
     * 授信额度管理-授信额度详情
     * @author 伍将
     * @date 2020/8/21
     **/
    @RequestMapping(value = "/getCreditDetail", method = RequestMethod.GET)
    public Wrapper<CreditDetailVO> getDetail(HttpServletRequest httpRequest, Long id) {
        return creditService.getDetail(getSysUser(httpRequest), id, false);
    }

    /**
     * 授信额度管理-授信额度详情-查询账单详情
     * @author 伍将
     * @date 2020/8/28
     **/
    @RequestMapping(value = "/getCreditBillDetail", method = RequestMethod.GET)
    public Wrapper<CreditBillDetailVO> getBillDetail(HttpServletRequest httpRequest, Long id) {
        return billService.getDetail(getSysUser(httpRequest),id);
    }

    /**
     * 授信额度管理-授信额度详情-分页查询交易记录
     * @author 伍将
     * @date 2020/8/21
     **/
    @RequestMapping(value = "/pageCreditTradeRecord", method = RequestMethod.GET)
    public Wrapper<PageData<CreditTradeRecordPageQueryVO>> pageTradeRecord(@Valid PageQueryCreditTradeRecordVO pageVO) {
        return tradeRecordService.pageTradeRecord(pageVO);
    }

    /**
     * 授信额度管理-授信额度详情-分页查询逾期
     * @author 伍将
     * @date 2020/8/24
     **/
    @RequestMapping(value = "/pageCreditOverdue", method = RequestMethod.GET)
    public Wrapper<PageData<CreditOverduePageQueryVO>> pageOverdue(PageQueryCreditOverdueVO pageVO) {
        return billService.pageOverdue(pageVO);
    }

    /**
     * 授信额度管理-授信额度详情-立即还款
     * @author 伍将
     * @date 2020/8/25
     **/
    @RequestMapping("/creditRepay")
    public Wrapper<CreditRepayResultVO> creditRepay(HttpServletRequest httpRequest, @RequestBody @Valid CreditRepayVO vo) {
        return creditService.repay(getSysUser(httpRequest), vo, httpRequest);
    }

    /**
     * 授信额度管理-授信额度详情-查询还款结果
     * @author 伍将
     * @date 2020/11/25
     **/
    @RequestMapping(value = "/getCreditRepayResult", method = RequestMethod.GET)
    public Wrapper<CreditRepayResultVO> getCreditRepayResult(HttpServletRequest httpRequest, Long recordId) {
        return creditService.getCreditRepayResult(getSysUser(httpRequest), recordId);
    }

    /**
     * 授信申请单查询-分页查询授信申请
     * @author 伍将
     * @date 2020/8/20
     **/
    @RequestMapping(value = "/pageCreditApply", method = RequestMethod.GET)
    public Wrapper<PageData<CreditApplyPageQueryVO>> pageCreditApply(HttpServletRequest httpRequest, PageQueryCreditApplyVO pageVO) {
        return creditApplyService.pageApplyByLower(getSysUser(httpRequest), pageVO);
    }

    /**
     * 待提交授信申请单-分页查询授信申请
     * @author 伍将
     * @date 2020/8/20
     **/
    @RequestMapping(value = "/pageWaitSubmitCreditApply", method = RequestMethod.GET)
    public Wrapper<PageData<CreditApplyPageQueryVO>> pageWaitSubmitApplyByApply(HttpServletRequest httpRequest, PageQueryCreditApplyVO pageVO) {
        return creditApplyService.pageWaitSubmitApplyByLower(getSysUser(httpRequest), pageVO);
    }

    /**
     * 待提交授信申请单-提交授信申请单-提交
     * @author 伍将
     * @date 2020/8/17
     **/
    @RequestMapping("/addCreditApply")
    public Wrapper<Long> addCreditApply(HttpServletRequest httpRequest, @RequestBody @Valid CreditApplyAddVO addVO) {
        return creditApplyService.add(getSysUser(httpRequest), addVO);
    }

    /**
     * 待提交授信申请单-提交
     * @author 伍将
     * @date 2020/8/19
     **/
    @RequestMapping("/submitCreditApply")
    public Wrapper<Void> submitCreditApply(HttpServletRequest httpRequest, @RequestBody CreditApplySubmitVO submitVO) {
        return creditApplyService.submit(getSysUser(httpRequest), submitVO);
    }

    /**
     * 待提交授信申请单-删除
     * @author 伍将
     * @date 2020/8/20
     **/
    @RequestMapping("/deleteCreditApply")
    public Wrapper<Void> delete(HttpServletRequest httpRequest, @RequestBody CreditApplySubmitVO vo) {
        return creditApplyService.delete(getSysUser(httpRequest), vo);
    }

    /** 获取授信申请单详情
     * @author 伍将
     * @date 2020/8/18
     **/
    @RequestMapping(value = "/getApplyDetail", method = RequestMethod.GET)
    Wrapper<CreditApplyDetailVO> getApplyDetail(HttpServletRequest httpRequest, @Valid CreditApplyGetDetailVO getDetailVO) {
        return creditApplyService.getDetail(getSysUser(httpRequest), getDetailVO, false);
    }

    /**
     * 分页查询会员列表页面搜索条件内容
     * @author 伍将
     * @date 2020/10/16
     **/
    @RequestMapping(value = "/pageItemsByConsumer", method = RequestMethod.GET)
    Wrapper<CreditPageItemsVO> pageItemsByConsumer(HttpServletRequest httpRequest) {
        return creditService.pageItemsByConsumer(getSysUser(httpRequest));
    }
}
